package com.app.qbake.module.square.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wind.base.adapter.BaseAdapterDelegate;
import com.wind.base.adapter.DisplayItem;
import com.wind.base.utils.ViewInflater;
import com.wind.data.square.bean.SquareItem;
import com.app.qbake.R;
import com.app.qbake.module.square.activity.GoodsDetailActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wind on 2018/10/28.
 */

public class SearchGoodsDelegate extends BaseAdapterDelegate<SearchGoodsDelegate.ViewHolder> {


    public SearchGoodsDelegate(Activity activity, int layoutRes) {
        super(activity, layoutRes);
    }

    @Override
    protected ViewHolder onCreateViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    protected boolean isForViewType(@NonNull List<DisplayItem> items, int position) {
        return true;
    }

    @Override
    protected void onBindViewHolder(@NonNull List<DisplayItem> items, int position, @NonNull RecyclerView.ViewHolder holder, @NonNull List<Object> payloads) {

        final SquareItem item= (SquareItem) items.get(position);
        ViewHolder vh= (ViewHolder) holder;
        ViewInflater.inflateImage(vh.iv_avatar,item.getAvatar());
        ViewInflater.inflateImage(vh.iv,item.getImages_url().get(0));
        ViewInflater.inflateText(vh.tv_title,item.getTitle());
        ViewInflater.inflateText(vh.tv_price,"￥"+item.getPrice());
        vh.tv_time.setText(item.getLast_login_time()+"活跃");

        vh.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoodsDetailActivity.start(mActivity,item.getId());
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.iv_avatar)
        ImageView iv_avatar;

        @BindView(R.id.iv)
        ImageView iv;

        @BindView(R.id.tv_title)
        TextView tv_title;
        @BindView(R.id.tv_price)
        TextView tv_price;

        @BindView(R.id.tv_time)
        TextView tv_time;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
